import BaseService from "./BaseService";
import { ConnectType } from "../NetConfig";
import WXHttpService from "./WXHttpService";
import WebHttpService from "./WebHttpService";
import WXSocketService from "./WXSocketService";
import WebSocketService from "./WebSocketService";
import WXCloudService from "./WXCloudService";
import QQCloudService from "./QQCloudService";
import BaiDuCloudService from "./SwanCloudService";

export default class ServiceBuilder {

    static getService(messageType: string, url: string, port?: number) {

        let service: BaseService = null;

        switch (messageType) {
            case ConnectType.HTTP:
                //这里如果是laya需要换成laya的判断方式
                if (window['wx']) {
                    service = new WXHttpService(url, port);
                } else {
                    service = new WebHttpService(url, port);
                }
                break;
            case ConnectType.WEB_SOCKET:
                if (window['wx']) {
                    service = new WXSocketService(url, port);
                } else {
                    service = new WebSocketService(url, port);
                }
                break;
            case ConnectType.CLOUD:
                if (window['qq']) {
                    service = new QQCloudService(url, port)
                } else if (window['wx']) {
                    service = new WXCloudService(url, port)
                } else if (window['swan']) {
                    service = new BaiDuCloudService(url, port)
                } else {
                    console.error('该平台不支持云开发')
                }
                break;
            default:
                break;
        }
        return service;
    }
}
